package com.sulj;

import com.sulj.domain.Fruit;
import com.sulj.domain.Order;
import com.sulj.enums.FruitType;
import com.sulj.service.ShoppingService;

import java.math.BigDecimal;

/**
 * 超市做促销活动，草莓限时打 8 折。
 * 现在顾客 C 在超市购买了若干斤苹果、 草莓和芒果，需计算一共需要多少钱？
 * 请编写函数，对于 C 购买的水果斤数 (水果斤数为大于等于 0 的整数)，计算并返回所购买商品的总价
 *
 * @author slj
 * @date 2025-03-29
 */
public class ThirdQuestion {

    public static void main(String[] args) {
        testCase(3, 5, 2, "116.0");
        testCase(0, 4, 3, "101.6");
        testCase(5, 0, 4, "120.0");
        testCase(2, 3, 0, "47.2");
    }

    private static void testCase(int appleQuantity, int strawberryQuantity, int mangoQuantity, String expected) {
        Fruit apple = new Fruit(FruitType.APPLE, "苹果", new BigDecimal("8"));
        Fruit strawberry = new Fruit(FruitType.STRAWBERRY, "草莓", new BigDecimal("13"), new BigDecimal("0.8"));
        Fruit mango = new Fruit(FruitType.MANGO, "芒果", new BigDecimal("20"));

        Order order = new Order();
        order.setCustomerName("顾客C");
        order.addItem(apple, appleQuantity);
        order.addItem(strawberry, strawberryQuantity);
        order.addItem(mango, mangoQuantity);

        ShoppingService shoppingService = new ShoppingService();
        BigDecimal total = shoppingService.calculateGrandTotal(order);
        System.out.printf("测试结果：%s购买 %s %d斤 + %s %d斤 + %s %d斤 = %s ，预期：%s ，验证结果%s%n",
                order.getCustomerName(),
                apple.getName(),
                appleQuantity,
                strawberry.getName(),
                strawberryQuantity,
                mango.getName(),
                mangoQuantity,
                total, expected,
                total.equals(new BigDecimal(expected)) ? "正确" : "错误");
    }
}
